<template>
  <div>
    <table-where :forms="forms" @onSubmit="onSubmit"></table-where>
    <wms-table ref="tableQuery" :tableDatas="tableDatas" @editHandle="editHandle"></wms-table>
  </div>
  <!-- <div v-if="!edit">
    <table-where :forms="editForms" @onSubmit="onSubmit2"></table-where>
  </div> -->
  <el-drawer v-model="edit" title="修改库区" show-close :close-on-click-modal="false" size="50%">
    <table-where :forms="editForms"></table-where>
  </el-drawer>
</template>

<script setup name="库区">
import { ref, reactive } from 'vue'
import { POSTJSON } from '@/components/utils/http'
import { useWmsGlobal } from '@/store/wmsGlobal'
const wmsGlobal = useWmsGlobal()
const edit = ref(false)
const tableDatas = reactive({
  body: {
    //表数据
    head: 'storeArea',
    url: '/Information/getStoreAreaPage',
    params: {},
    type: 'POSTJSON'
  },
  delete: {
    url: '/Information/deleteStoreArea',
    params: { id: 'id' }
  },
  edit: {
  }
})
const tableQuery = ref()

const onSubmit = () => {
  tableQuery.value.getData()
}
const forms = reactive({
  data: tableDatas.body.params,
  rules: [],
  compValue: [
    { label: '名称', value: 'name', type: 'iconinput' },
    {
      label: '新增',
      type: 'button',
      onclick: () => {
        edit.value = true
        editForms.data = {store_area_stat:1}
      }
    },
    { label: '查询', type: 'button', onclick: onSubmit }
  ]
})
const editForms = reactive({
  data: {},
  rules: [],
  compValue: [
    { label: '名称', value: 'name', type: 'input' },
    { label: '库区类型', value: 'store_area_type', type: 'select',options: wmsGlobal.wmsOptions['store_area_type'] },
    { label: '状态', value: 'store_area_stat', type: 'select',options: wmsGlobal.wmsOptions['store_area_stat'] },
    {
      label: '保存',
      type: 'button',
      onclick: () => {
        POSTJSON('/Information/addOrUpdateStoreArea', editForms.data).then(data => {
          if (data.code > 0) {
            editForms.data = {}
          }
        })
      }
    },
    {
      label: '返回',
      type: 'button',
      onclick: () => {
        edit.value = false
      }
    }
  ]
})
const editHandle = ({ row }) => {
  edit.value = true
  editForms.data = Object.assign({}, row)
}
</script>
